﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EarTag.API.Application.MediatorCommand.AppearanceCommand;
using S.EarTag.API.Mediator.MediatorCommand.AppearanceCommand;
using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;

namespace S.EarTag.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AppearanceController : BaseController
    {
        private readonly IMediator _mediator;
        public AppearanceController(IMediator mediator,MySqlDbContext _db):base(_db)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 添加品相测量数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddAppearance(AppearanceCreateCommand command)
        {
            command.CreateBy = UserStrategyDto.UserTrueName;
            command.CreateDate= DateTime.Now;
            command.UpdateBy = "";
            command.UpdateDate = "";
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 批量删除品相测量数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> BatchRemoveAppearance(AppearanceBatchRemoveCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据id进行单挑数据删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> DeleteAppearance(int id)
        {
            AppearanceDeleteCommand command = new AppearanceDeleteCommand();
            command.AppearanceId = id;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据id进行修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UodAppearance(AppearanceUpdateCommand command)
        {
            command.UpdateBy = UserStrategyDto.UserTrueName;
            command.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var result=await _mediator.Send(command);
            return Ok(result);
        }
    }
}
